package com.bluebench.bigul;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import com.bluebench.bigul.domain.Element;
import com.bluebench.bigul.exception.GraphicInitializationException;
import com.bluebench.bigul.service.DocumentGenerator;
import com.bluebench.bigul.service.TemplateParser;
import com.bluebench.bigul.service.resolver.DefaultExpressionResolver;
import com.bluebench.bigul.service.resolver.ElementResolver;
import com.bluebench.bigul.utility.FileToStringConversion;
import com.itextpdf.text.DocumentException;


public class TestDocumentGeneration {
	
	//Parses the template to Element Object
	private TemplateParser parser;
	
	//Converts Element object to itext Document
	private DocumentGenerator generator;
	
		
	public TestDocumentGeneration() {
		parser = new TemplateParser();
		generator = new DocumentGenerator();
	}
	
	
	void generateDocument(){
		
		try {
			ElementResolver eResolver = (ElementResolver)DefaultExpressionResolver.getInstance(DefaultExpressionResolver.ELEMENT_RESOLVER);
			parser.setTemplateXml(FileToStringConversion.convertToString("D:/MyFolder/templates/TemplatesAndDocuments/template_graphic_2.xml"));
			Element element = parser.parse();
			generator.generateDocument("D:/MyFolder/templates/TemplatesAndDocuments/template_graphic_2.pdf",element);
			
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (SecurityException e1) {
			System.out.println("Security Exception");
			e1.printStackTrace();
		} catch (IllegalArgumentException e1) {
			System.out.println("Illegal Argument Exception");
			e1.printStackTrace();
		} catch (DocumentException e1) {
			System.out.println("Document Exception");
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			System.out.println("Class Not Found Exception");
			e1.printStackTrace();
		} catch (NoSuchMethodException e1) {
			System.out.println("No Such Method Exception");
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			System.out.println("Illegal Argument Exception");
			e1.printStackTrace();
		} catch (InvocationTargetException e1) {
			System.out.println("Invocation Target Exception");
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			System.out.println("Instatiation Exception");
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		} catch (NoSuchFieldException e1) {
			e1.printStackTrace();
		} catch (GraphicInitializationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		TestDocumentGeneration tdg = new TestDocumentGeneration();
		tdg.generateDocument();
		
		
	}
	
	
	
}
